<template>
  <div class="app-container">
    <div>
      <!-- 条件栏 -->
      <NewPageFilter
        v-model:query="filterInfo.query"
        :filter-btn="filterInfo.searchBtn"
        :filter-list="filterInfo.searchList"
      >
      </NewPageFilter>
      <!-- 表格 -->
      <table-container
        :refresh="tableInfo.refresh"
        :init-curpage="tableInfo.initCurpage"
        v-model:data="tableInfo.data"
        :api="tableInfo.api"
        :query="filterInfo.query"
        :field-list="tableInfo.fieldList"
        :check-box="false"
        :tab-index="true"
        :handle="tableInfo.handle"
      >
      </table-container>
    </div>
  </div>
</template>

<script setup name="pendSaleOrder">
import TableContainer from '@/components/TableContainer/index'
import { getPendSaleOrderPage, pendSaleOrderRefuse } from '@/api/supplier.js'

const { proxy } = getCurrentInstance()
// 过滤相关配置
const filterInfo = reactive({
  query: {
    sort: 'order_no desc',
    orderNo: '',
    purchProductType: '',
  },
  searchList: [
    {
      componentType: 'input',
      label: '采购单号',
      value: 'orderNoLike',
      clearable: true,
      event: search,
    },
    {
      label: '采购类型',
      value: 'purchProductType',
      componentType: 'select-model',
      code: 'order_product_type',
      event: search,
      clearable: true,
    },
  ],
  searchBtn: [
    { type: 'button', label: '搜索', event: search },
    { type: 'button', label: '重置', event: clearSearch },
  ],
})
// 表格相关
const tableInfo = reactive({
  refresh: 1,
  initCurpage: 1,
  data: [{ orderNo: 1 }],
  api: getPendSaleOrderPage,
  selections: [],
  fieldList: [
    { label: '采购单号', value: 'orderNo' },
    { label: '采购类型', value: 'purchProductTypeValue' },
    { label: '创建人', value: 'createUserName' },
    { label: '创建时间', value: 'createTime' },
    { label: '备注', value: 'remark' },
  ],
  handle: {
    fixed: 'right',
    label: '操作',
    width: '100',
    btList: [
      {
        label: '接收',
        event: receive,
        show: true,
      },
      {
        label: '拒绝',
        event: reject,
        popconfirmText: '拒绝后将不能对改采购单销售,是否继续？',
        show: true,
      },
    ],
  },
})

onMounted(() => {
  getList()
})

// 获取列表
function getList() {
  tableInfo.refresh = Math.random()
}
// 搜索
function search() {
  // 重置分页
  tableInfo.initCurpage = Math.random()
  tableInfo.refresh = Math.random()
}
function receive(row) {
  proxy.$router.push({
    name: 'saleOrder',
    params: row,
  })
}
function reject(row) {
  let param = [
    {
      id: row.id,
      purchType: row.purchType,
    },
  ]
  pendSaleOrderRefuse(param).then((res) => {
    if (res && res.success) {
      getList()
    }
  })
}
function clearSearch() {
  filterInfo.query.orderNoLike = ''
  filterInfo.query.purchProductType = ''
  getList()
}
</script>

<style scoped lang="scss">
:deep(.el-table .warning-row) {
  background: #f5e4e4;
}

// :deep(.el-table__body tr.hover-row > td) {
//   background-color: transparent !important;
// }
</style>
